import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/Pages/login.vue'


Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      redirect:'/login'
    },
    {
      path: '/login',
      name: 'login',
      component:Login
    },
    {
      path: '/home',
      name: 'home',
      // 路由重定向
      redirect:'/order-manage',
      component: () => import(/*webpackChunkName:"home"*/ '@/pages/home.vue'),
      children: [
        {
          path: '/user-manage',
          name: 'user-manage',
          // 路由懒加载，达到高效加载页面，把该路由下的所有组件打包到同一个异步块
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/user-manage/index.vue'),
        },
        {
          path: '/test',
          name: 'test',
          // 路由懒加载，达到高效加载页面，把该路由下的所有组件打包到同一个异步块
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/user-manage/test.vue'),
        },
        {
          path: '/test1',
          name: 'test1',
          // 路由懒加载，达到高效加载页面，把该路由下的所有组件打包到同一个异步块
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/user-manage/test1.vue'),
        },
        {
          path: '/menu-manage',
          name: 'menu-manage',
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/menu-manage/index.vue'),
        },
        {
          path: '/comm-manage',
          name: 'comm-manage',
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/comm-manage/index.vue'),
        },
        {
          path: '/home-pic-manage',
          name: 'home-pic-manage',
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/home-pic-manage/index.vue'),
        },
        {
          path: '/comm-classify-manage',
          name: 'comm-classify-manage',
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/comm-classify-manage/index.vue'),
        },
        {
          path: '/client-manage',
          name: 'client-manage',
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/client-manage/index.vue'),
        },
        {
          path: '/order-manage',
          name: 'order-manage',
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/order-manage/index.vue'),
        },
        {
          path: '/hot-comm-manage',
          name: 'hot-comm-manage',
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/hot-comm-manage/index.vue'),
        },
        {
          path: '/shop-info-manage',
          name: 'shop-info-manage',
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/shop-info-manage/index.vue'),
        },
        {
          path: '/driver-info-manage',
          name: 'driver-info-manage',
          component: () => import(/*webpackChunkName:"home"*/ '@/pages/driver-info-manage/index.vue'),
        },

      ]
    }
    
  ]
})

//  路由导航守卫挂载
// router.beforeEach((to, from, next) => {
//   // to 将要访问的路径
//   // from  代表从哪个路径跳转而来
//   // next  是一个函数，表示放行
//   // next()---放行     next('/login')强制跳转
//   if (to.path === '/login') {
//     return next()
//   };
//   // 如果没有登陆成功获取到token，就定向在登入页面
//   const takenStr = window.sessionStorage.getItem('role').role;
  
//   if (takenStr === 2) {
//     return next('/order-manage')
//   }
//   else next()  
// })


// export default router